
*File to join game user data and PM2p5 data for in zip monitors

***Inputs 
* $Data/aqs_user_zips.dta
* $Data/GameUser_zd.dta
* $Data/daily_PM2p5_1318.dta

***Output 
* $Data/GameUser_pollution_zd_inzip.dta


***1. GET MONITOR LOCATIONS FOR EACH DATE THAT WE NEED DATA FOR***

* tell us which monitors to match users to 

	use $Data/aqs_user_zips.dta, clear   
	   
	* tell us which dates to get pollution data for 
	 joinby zip using $Data/GameUser_zd.dta, unmatched(master)
	drop _merge

	   
	***2. MERGE POLLUTION DATA FOR EACH DATE AND LOCATION AND MONITOR***

	merge m:1 statecode countycode sitenumber date using $Data/daily_PM2p5_1318.dta

	drop if _merge ==2 // 

	drop _merge


	
collapse (mean) dailypm25 = mean_pollution  , by(zip date) // average over monitors

save $Data/GameUser_pollution_zd_inzip.dta, replace






